<?php

/* @var $this yii\web\View */

use yii\helpers\Url;
use yii\helpers\Html;
use common\helpers\Render;
use common\models\EmploymentSalary;

$this->addCrumbs('薪酬发放列表', 'employment/salary-list');
$this->title = '薪酬结算';
?>

<div class="box-content gap">
    <div class="flyer-form pane">
        <div class="form-item">
            <div class="item-inline">
                <div class="input-title">雇主</div>
                <div class="input-inline input-mid"><?= $data->employer_id.':'.Html::encode($data->employer->username) ?></div>
            </div>
            <div class="item-inline">
                <div class="input-title">设计师</div>
                <div class="input-inline input-mid"><?= $data->designer_id.':'.Html::encode($data->designer->username) ?></div>
            </div>
        </div>
        <div class="form-item">
            <div class="item-inline">
                <div class="input-title">手机号</div>
                <div class="input-inline input-mid"><?= Render::value($data, 'designer.mobile') ?></div>
            </div>
            <div class="item-inline">
                <div class="input-title">邮箱</div>
                <div class="input-inline input-mid"><?= Render::value($data, 'designer.email', '--') ?></div>
            </div>
        </div>
        <div class="form-item">
            <div class="item-inline">
                <div class="input-title">支付宝账号</div>
                <div class="input-inline input-mid"><?= Render::value($data, 'designer.alipay_account', '--') ?></div>
            </div>
            <div class="item-inline">
                <div class="input-title">微信账号</div>
                <div class="input-inline input-mid"><?= Render::value($data, 'designer.wechat_account', '--') ?></div>
            </div>
        </div>
        <div class="form-item">
            <div class="item-inline">
                <div class="input-title">薪酬计算时间</div>
                <div class="input-inline input-mid"><?= date('Y-m-d', strtotime($data->begin)).' ~ '.date('Y-m-d', strtotime($data->finish)) ?></div>
            </div>
            <div class="item-inline">
                <div class="input-title">结算日期</div>
                <div class="input-inline input-mid"><?= date('Y-m-d', strtotime($data->paydate)) ?></div>
            </div>
        </div>
        <div class="form-item item-text">
            <div class="input-title">备注</div>
            <div class="input-block input-mid pd-10px"><?= Render::value($data, 'remark', '--') ?></div>
        </div>
        <div class="form-item item-text">
            <div class="item-inline">
                <div class="input-title">状态</div>
                <div class="input-inline input-mid"><?= Render::show(EmploymentSalary::$statusSelector, $data->status) ?></div>
            </div>
            <div class="item-inline">
                <div class="input-title">发放时间</div>
                <div class="input-inline input-mid"><?= ($data->status == EmploymentSalary::StatusSuccess) ? date('Y-m-d H:i:s', $data->success_at) : '--' ?></div>
            </div>
        </div>
    </div>
    <?php
    if($data->canSettle()) {
        ?>
    <div class="data-title mt-20px mb-10px">修改结算状态</div>
    <form class="flyer-form pane" id="flyer-create" method="post">
        <div class="form-item item-text">
            <div class="input-title">备注</div>
            <div class="input-block"><textarea class="flyer-textarea" name="remark" placeholder="remark."><?= Render::value($data, 'remark') ?></textarea></div>
        </div>
        <div class="form-item">
            <div class="input-block tr bdn">
                <button class="flyer-button normal border-round" id="settle-button" type="button" data-href="<?= Url::to('@web/employment/salary-settle?id='.$data->id) ?>"><i class="icon-ok"></i> 已结算</button>
                <button class="flyer-button danger border-round" id="close-button" type="button" data-href="<?= Url::to('@web/employment/salary-close?id='.$data->id) ?>"><i class="icon-remove"></i> 关闭</button>
            </div>
        </div>
        <input type="hidden" name="_csrf" value="<?=Yii::$app->request->getCsrfToken() ?>">
    </form>
    <?php
        }
        ?>
</div>
<script src="<?= Render::static('flyer/flyer.class.js') ?>"></script>
<script src="<?= Render::static('flyer/checker.class.js') ?>"></script>
<script>
    $(document).ready(function() {
        // Form 元素初始化
        (new flyer).init({ form: '#flyer-create' });
        // 提交按钮绑定事件
        $('#settle-button, #close-button').bind('click', function() {
            $('#flyer-create').attr('action', $(this).attr('data-href')).submit();
        });
    });
</script>